<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <h2>数据成功嵌入模板生成domStr</h2>
    <div id="domstr"></div>

    <script type="text/template" id="myTemplate">
      <div>
        <ol>
          {{#students}}
          <li>
            学生{{name}}的爱好是
            <ol>
              {{#hobbies}}
              <li>{{.}}</li>
              {{/hobbies}}
            </ol>
          </li>
          {{/students}}
        </ol>
      </div>
    </script>
    <script src="/www/bundle.js"></script>
    <script>
      // 模板字符串
      var templateStr = document.getElementById('myTemplate').textContent.trim()
      // 数据
      var data = {
        students: [
          { name: '小明', hobbies: ['足球', '音乐'] },
          { name: '小红', hobbies: ['羽毛球', '美术', '跑步'] },
          { name: '小强', hobbies: ['篮球', '睡觉'] }
        ]
      }
      // 调用模板引擎的render
      var domStr = window.ywl_TemplateEngine.render(templateStr, data)
      document.getElementById('domstr').innerHTML = domStr
      console.log(domStr)
    </script>
  </body>
</html>
